﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using EasierRdp.Models;
using EasierRdp.Util;

namespace EasierRdp
{
    partial class UserDialog : Form
    {
        public RdpUser User { get; set; }

        public UserDialog()
        {
            InitializeComponent();
        }

        private void UserDialog_Load(object sender, EventArgs e)
        {
            if (User != null)
            {
                Text_Name.Text = User.Name;
                Text_Pass.Text = User.Password;
                if (!String.IsNullOrEmpty(User.Password))
                {
                    CheckBox_SavePassword.Checked = true;
                }
            }
        }

        private void Button_Ok_Click(object sender, EventArgs e)
        {
            if (User == null)
            {
                User = new RdpUser(Text_Name.Text);
            }
            else
            {
                User.Name = Text_Name.Text;
            }
            User.Password = Text_Pass.Text;
            User.SavePassword = CheckBox_SavePassword.Checked;
            RdpContext.AddUser(User);
            this.DialogResult = DialogResult.OK;
            this.Hide();
            EasierRdpEvents.MainForm.Invoke(new EasierRdpEvents.VoidDelegate(EasierRdpEvents.MainForm.RebindTree));
        }

        private void Button_Cancel_Click(object sender, EventArgs e)
        {
            this.Hide();
        }
    }
}
